<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:wadl="http://research.sun.com/wadl/2006/10"
	exclude-result-prefixes="wadl"
	>

  <xsl:template match="/wadl:application">
  	<html>
	  	<head>
	  		<style>
	  			body {
	  				font-family: Calibri;
	  			}
	  			.doc {
	  				color:silver;
	  			}
	  			.required {
	  				color: brown;
	  			}
	  			.resource-body {
	  				padding-left: 20px;
						border-style: dashed;
						border-width: 1px;
						border-color: black;
					}
	  			.method-body {
	  				margin-left: 20px;
	  			}
	  			h3 {
	  				background-color: black;
	  				color: white;
	  				margin-bottom: -1px;
	  				padding-left: 6px;
	  				padding-top: 3px;
	  				padding-bottom: 3px;
	  				font-size: 14pt;
	  			}
	  			h4 {
	  				font-size: 12pt;
	  				margin-bottom: -5px;
	  			}
	  			h5 {
	  				margin-bottom: 10px;
	  				margin-top: -5px;
	  				font-size: 12pt;
	  				color: brown;
	  			}
	  			h6 {
	  				margin-bottom: -10px;
	  				margin-top: -5px;
	  				font-size: 12pt;
	  			}
	  		</style>
	  	</head>
	  	<body>
				<h1>Application</h1>
				<xsl:apply-templates select="wadl:doc" />
				
				<h2>XML Schemas</h2>
				<ul>
				<xsl:for-each select="wadl:grammars/wadl:include">
					<li><a><xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute><xsl:value-of select="@href" /></a></li>
				</xsl:for-each>
				</ul>
				
				<h2>Resources</h2>
				<div>Base: <a><xsl:attribute name="href"><xsl:value-of select="wadl:resources/@base" /></xsl:attribute><xsl:value-of select="wadl:resources/@base" /></a></div>
		  
		  	<xsl:apply-templates select="wadl:resources/wadl:resource" />
	  	</body>
  	</html>
  </xsl:template>
  
  <xsl:template match="wadl:resource">
		<h3><xsl:for-each select="ancestor-or-self::wadl:resource">/<xsl:value-of select="@path" /></xsl:for-each></h3>
		<div class="resource-body">
	
			<xsl:apply-templates select="wadl:doc" />
			
			<h4>Path parameters</h4>
			<ul>
					<xsl:for-each select="ancestor-or-self::wadl:resource">
						<xsl:apply-templates select="wadl:param" />
					</xsl:for-each>
			</ul>
	
			<xsl:apply-templates select="wadl:method" />

		</div>
  	<xsl:apply-templates select="wadl:resource" />
  </xsl:template>

	<xsl:template match="wadl:doc">
		<div class="doc"><xsl:copy-of select="." /></div>
	</xsl:template>

	<xsl:template match="wadl:param">
		<li>
			<b><xsl:value-of select="@name" /></b> as <xsl:value-of select="@style" />
			(<xsl:if test="@required"><span class="required">required</span></xsl:if>)
			<xsl:apply-templates select="wadl:doc" />
		</li>
	</xsl:template>

	<xsl:template match="wadl:representation">
		<li><div>
			<b><xsl:value-of select="@status" /></b>: <xsl:value-of select="@mediaType" /> with &lt;<xsl:value-of select="@element" />&gt;
			<xsl:apply-templates select="wadl:doc" />
		</div></li>
	</xsl:template>

	<xsl:template match="wadl:fault">
		<li><div>
			Possible fault codes: <b><xsl:value-of select="@status" /></b>
		</div></li>
	</xsl:template>

	<xsl:template match="wadl:method">
		<h5><xsl:value-of select="@name" /></h5>
		<div class="method-body">
			<xsl:apply-templates select="wadl:doc" />
	
			<h6>Request parameters</h6>
			<ul>
					<xsl:apply-templates select="wadl:request/wadl:param" />
			</ul>
			
			<h6>Response</h6>
			<ul>
				<xsl:apply-templates select="wadl:response/wadl:representation" />
				<xsl:apply-templates select="wadl:response/wadl:fault" />
			</ul>
		</div>
	</xsl:template>

</xsl:stylesheet>